package subject_set.top101;

/**
 * @author haomin
 * @date 2022/11/02 20:37
 **/
public class BM29 {
    public class Solution {
        boolean flag = false;
        public boolean hasPathSum (TreeNode root, int sum) {
            dfs(root, sum);
            return flag;
        }
        private void dfs(TreeNode root, int sum){
            if(root == null) return;
            sum -= root.val;
            if(root.left == null && root.right == null){
                if(sum == 0) flag = true;
                return;
            }
            dfs(root.left, sum);
            dfs(root.right, sum);
        }
    }
}